package com.youchuang.action.indent;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.youchuang.action.BaseAction;
import com.youchuang.bean.ReceiveAddress;
import com.youchuang.bean.User;
import com.youchuang.common.Constant;
import com.youchuang.service.IndentService;

import net.sf.json.JSONArray;

/**
 * 查找地址
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/indent")
@ParentPackage("shopping-default")
public class AddressAction extends BaseAction {

	private Logger logger = Logger.getLogger(AddressAction.class.getSimpleName());
	private List<ReceiveAddress> receiveAddressList;
	@Resource
	private IndentService indentService;

	@Action(value = "address", interceptorRefs = { @InterceptorRef(value = "loginStack") }, results = {
			@Result(name = Constant.SUCCESS, type = "json") })
	public String execute() throws Exception {
		logger.info("execetion is execute");
		String userId = ((User) session.get(Constant.S_USER)).getId();

		receiveAddressList = indentService.findReceiveAddressByUserId(userId);
		
		logger.info("response json = " + JSONArray.fromObject(receiveAddressList).toString());
		return Constant.SUCCESS;
	}

	public List<ReceiveAddress> getReceiveAddressList() {
		return receiveAddressList;
	}

	public void setReceiveAddressList(List<ReceiveAddress> receiveAddressList) {
		this.receiveAddressList = receiveAddressList;
	}

}
